﻿using System;
using System.Collections.Generic;
using System.Text;
using System.Web;
using System.Web.UI;
using Hxsoft.AppV1.Module;
using Hxsoft.AppV1.WebUI;

namespace Hxsoft.AppV1._Controls
{
	[Serializable]
	public partial class LinkDisplay : LinkList, IIncludeFile
	{
		public override int? SiteId
		{
			get
			{
				if(!LoadSiteId.HasValue)
					return base.SiteId;
				return LoadSiteId;
			}
		}

		private LoadedValue<int?> loadedLoadSiteId;
		public int? LoadSiteId
		{
			get {
				if (loadedLoadSiteId.Loader == null)
					loadedLoadSiteId.Loader = () => (int?)ViewState["LoadSiteId"];
				return loadedLoadSiteId.Value;
			}
			set {
				if (loadedLoadSiteId.Setter == null)
					loadedLoadSiteId.Setter = v => ViewState["LoadSiteId"] = v;
				loadedLoadSiteId.Value = value;
			}
		}

		public string ContainerCss
		{
			get { return CtrImageDisplay.ContainerCss; }
			set { CtrImageDisplay.ContainerCss = value; }
		}
		
		public string PagerCss
		{
			get { return CtrImageDisplay.PagerCss; }
			set { CtrImageDisplay.PagerCss = value; }
		}
		
		public string TextCss
		{
			get { return CtrImageDisplay.TextCss; }
			set { CtrImageDisplay.TextCss = value; }
		}

		public string LinkTarget
		{
			get { return CtrImageDisplay.LinkTarget; }
			set { CtrImageDisplay.LinkTarget = value; }
		}
		
		public ImageDisplayTextPlace TextPlace
		{
			get { return CtrImageDisplay.TextPlace; }
			set { CtrImageDisplay.TextPlace = value; }
		}

		public ImageDisplayPagerPlace PagerPlace
		{
			get { return CtrImageDisplay.PagerPlace; }
			set { CtrImageDisplay.PagerPlace = value; }
		}

		public JQueryCycleEffect DisplayEffect
		{
			get { return CtrImageDisplay.DisplayEffect; }
			set { CtrImageDisplay.DisplayEffect = value; }
		}

		public JQueryEasing Easing
		{
			get { return CtrImageDisplay.Easing; }
			set { CtrImageDisplay.Easing = value; }
		}

		public JQueryEasing EaseIn
		{
			get { return CtrImageDisplay.EaseIn; }
			set { CtrImageDisplay.EaseIn = value; }
		}

		public JQueryEasing EaseOut
		{
			get { return CtrImageDisplay.EaseOut; }
			set { CtrImageDisplay.EaseOut = value; }
		}

		public int? Speed
		{
			get { return CtrImageDisplay.Speed; }
			set { CtrImageDisplay.Speed = value; }
		}

		public int? SpeedIn
		{
			get { return CtrImageDisplay.SpeedIn; }
			set { CtrImageDisplay.SpeedIn = value; }
		}

		public int? SpeedOut
		{
			get { return CtrImageDisplay.SpeedOut; }
			set { CtrImageDisplay.SpeedOut = value; }
		}

		public bool? Sync
		{
			get { return CtrImageDisplay.Sync; }
			set { CtrImageDisplay.Sync = value; }
		}

		public int? Delay
		{
			get { return CtrImageDisplay.Delay; }
			set { CtrImageDisplay.Delay = value; }
		}

		public int? Timeout
		{
			get { return CtrImageDisplay.Timeout; }
			set { CtrImageDisplay.Timeout = value; }
		}

		public int? ShuffleTop
		{
			get { return CtrImageDisplay.ShuffleTop; }
			set { CtrImageDisplay.ShuffleTop = value; }
		}

		public int? ShuffleLeft
		{
			get { return CtrImageDisplay.ShuffleLeft; }
			set { CtrImageDisplay.ShuffleLeft = value; }
		}

		public override bool RandomSort
		{
			get { return CtrImageDisplay.RandomSort; }
			set { CtrImageDisplay.RandomSort = value; }
		}

		public string PagerEvent
		{
			get { return CtrImageDisplay.PagerEvent; }
			set { CtrImageDisplay.PagerEvent = value; }
		}

		public override bool ShowDefaultUrl
		{
			get { return CtrImageDisplay.ShowDefaultUrl; }
			set { CtrImageDisplay.ShowDefaultUrl = value; }
		}

		public override string ItemImageResourceCopyName
		{
			get
			{
				return base.ItemImageResourceCopyName;
			}
			set
			{
				base.ItemImageResourceCopyName = value;
				CtrImageDisplay.LinkResourceCopyName = value;
			}
		}

		protected override void OnInit(EventArgs e)
		{
			CtrList = CtrImageDisplay.CtrImageList;
			CtrImageDisplay.DataLinkUrlField = "LinkUrl";
			CtrImageDisplay.DataTextField = "Title";
			CtrImageDisplay.DataLinkIdField = "LinkId";			
			CtrImageDisplay.GetImageUrlMethod = GetImageUrlMethod;
			base.OnInit(e);			
		}

		public string GetImageUrlMethod(object o)
		{
			string image = DataBinder.Eval(o, "ImageType", null);
			if (image.EndsWith(".swf", StringComparison.CurrentCultureIgnoreCase))
				return GenericUrlManager.GetInfoResourceThumbnailGeneratorUrl(image, null);
			return GenericUrlManager.GetInfoResourceThumbnailGeneratorUrl(image, ItemImageResourceCopyName);
		}

		#region IIncludeFile 成员
		public Dictionary<string, IncludeFileType> GetHeadIncludeFiles()
		{
			return CtrImageDisplay.GetHeadIncludeFiles();
		}
		#endregion
	}
}